#include <stdio.h>
#include "opt.h"
#include "selector.h"
#include "sub.h"

static int show_help;
static int show_version;
static int target_gop;
static int inplace;

static const struct option_def optdef[] = {
	{OPT_FLAG, 'g', "gop", {.flag = &target_gop}, "gop mode", 0},
	{OPT_FLAG, 'i', "inplace", {.flag = &inplace}, "inplace edit", 0},
	{OPT_FLAG, 0, "help", {.flag = &show_help}, "show help", 0},
	{OPT_FLAG, 0, "version", {.flag = &show_version}, "show version", 0},
	{OPT_GROUP, 0, 0, {.group = &selector_options}, 0, 0},
	{.type = OPT_END},
};
static const struct option_group optgroup = {.defs = optdef};


static void usage(void)
{
	printf("Usage: %s [-gi] [selectors] ARG1 ARG2\n", prog);
}
void print_selector(void);
static void print_config(void)
{
	printf("flags:%s%s%s%s\n",
			show_help ? " help" : "",
			show_version ? " version" : "",
			target_gop ? " gop" : "",
			inplace ? " inplace" : "");
	print_selector();
}

int optdebug_main(int argc, const char *const *argv)
{
	const char *args[2] = {0};
	if (parse_options(argc, argv, &optgroup, 2, args) < 0) {
		usage();
		return 2;
	}
	if (show_help) {
		usage();
		print_options(&optgroup);
		return 0;
	}
	print_config();
	printf("args: %s %s\n", args[0], args[1]);
	return 0;
}
